# Untitled - By: lenovo - Fri Sep 6 2024

import sensor
import image
import time
import network

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

SSID = 'xxx.xxx.xxx.xxx'
KEY = ''

HOST = SSID
PORT = 8080

# wlan对象初始化
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, KEY)

while not wlan.isconnected():
    print('Trying to connect to ')
    time.sleep_ms(1000)

# 获取目标主机地址
addr = socket.getaddrinfo(HOST, PORT)[0][4]
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(addr)

while (True):
    img = sensor.snapshot()
    # 去畸变
    img.lens_corr(strength=1.8, zoom=1.0)
    cframe = img.compressed(quality=35)
    # 发送图片
    client.send(cframe)

client.close()
